<!DOCTYPE html>
<%--
  Created by IntelliJ IDEA.
  User: M
  Date: 2023/6/23
  Time: 11:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>裁剪生产计划</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.8.6/dist/css/layui.css" rel="stylesheet">
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <!-- 引入 layui.css -->
    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">

    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
</head>
<body onload="getProduts()">
<div id="addForm" style="display: none">
    <form class="layui-form" action="#" method="POST" id="fm">
        <div class="layui-form-item">
            <label class="layui-form-label">订单编号</label>
            <div class="layui-input-inline" style="width: 280px">
                <select name="orderId" lay-verify="required" class="layui-select">
                    <option value="" id="oop"></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">款号</label>
            <div class="layui-input-inline" style="width: 280px">
                <select name="styleNumberId" lay-verify="required" class="layui-select">
                    <option value="" id="syp"></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-inline" style="width: 280px">
                <select name="productDetailId" lay-verify="required" class="layui-select">
                    <option value="" id="prp"></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">尺寸</label>
            <div class="layui-input-inline" style="width: 280px">
                <select name="sizeId" lay-verify="required" class="layui-select">
                    <option value="" id="sop"></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">当天产量</label>
            <div class="layui-input-inline" style="width: 280px">
                <input type="text" name="producedCount" lay-verify="required|number" placeholder="请输入数量" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">生产计划</label>
            <div class="layui-input-inline" style="width: 280px">
                <select name="productionPlanId" lay-verify="required" class="layui-select">
                    <option value="" id="pop"></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-inline" style="width: 280px">
                <select name="departmentId" lay-verify="required" class="layui-select">
                    <option value="" id="dop"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<div class="layui-form layui-border-box layui-table-view" lay-filter="LAY-table-1" lay-id="demo" style=" height:312px;">
    <div class="layui-table-tool">
        <div class="layui-table-tool-self">
            <div class="layui-inline" title="筛选列" lay-event="LAYTABLE_COLS">
                <i class="layui-icon layui-icon-cols"></i>
            </div>
            <div class="layui-inline" title="导出" lay-event="LAYTABLE_EXPORT">
                <i class="layui-icon layui-icon-export"></i></div>
            <div class="layui-inline" title="打印" lay-event="LAYTABLE_PRINT">
                <i class="layui-icon layui-icon-print"></i></div>
        </div>
    </div>
    <div class="layui-table-box">
        <div class="layui-table-header">
            <table cellspacing="0" cellpadding="0" border="0" class="layui-table">
                <thead>
                <tr>
                    <th data-field="clientId" data-key="1-0-0" class=" layui-unselect">
            </table>
            <table id="demo" lay-filter="test"></table>
        </div>
    </div>
</div>

<script>
    layui.use('table', function () {
        var table = layui.table;
        //第一个实例
        table.render({
            elem: '#demo'
            , height: 312
            , url: 'contract/queryProductionPlan' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'productionPlanId', title: '生产计划编号', width: 151},
                {field: 'quotationNumber', title: '订单编号', width: 171},
                {field: 'styleNumber', title: '款号', width: 170},
                {field: 'scheduleTime', title: '排班日期', width: 147},
                {field: 'schedeleCount', title: '计划生产数量', width: 140},
                {field: 'productName', title: '商品名称', width: 147},
                {field: 'staffDepartment', title: '部门', width: 125},
                {field: 'name', title: '尺码', width: 85},
                {field: '', title: '  操作', width: 120, toolbar: "#barDemo"},
                {field: 'styleNumberId', title: '款号id', width: 150,hide:true},
                {field: 'OrderId', title: '订单id', width: 150,hide:true},
                {field: 'productDetailId', title: '商品id', width: 150,hide:true},
                {field: 'sizeId', title: '尺寸id', width: 150,hide:true}
            ]]
        });
    })
</script>
<script type="text/javascript">
</script>
<script type="text/html" id="barDemo">
    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
</script>

<script type="text/javascript">
    function getProduts() {
        $.ajax( {
            "url"            :  "contract/queryDepartment",
            "type"         :  "get",
            "data"         :  {},
            "dataType" :  "json",
            // contentType:"application/json;charset=utf-8",
            "success"  :  function(result) {
                let opo =''
                for (let ord in result) {
                    opo +=`
                    <option value="\${result[ord].id}">\${result[ord].staffDepartment}</option>
                    `
                }
                $('#dop').after(opo)
                layui.form.render('select'); // 重新渲染select元素
            },
            "error"       :  function() {
                alert("没有查询到部门")
            }
        } );
    }

        layui.use(['table', 'form'], function () {
            var table = layui.table;
            var form = layui.form;

            // 监听表格工具栏按钮点击事件
            table.on('tool(test)', function (obj) {
                var data = obj.data; // 获取当前行的数据
                if(obj.event === 'add'){

                    // 根据字段名称获取对应的值
                    var productionPlanId = data.productionPlanId;
                    var quotationNumber = data.quotationNumber;
                    var styleNumber = data.styleNumber;
                    var schedeleCount = data.schedeleCount;
                    var productName = data.productName;
                    var name = data.name;
                    var styleNumberId = data.styleNumberId;
                    var OrderId = data.orderId;
                    var productDetailId = data.productDetailId;
                    var sizeId = data.sizeId;
                    // 设置表单元素的值
                    $("#oop").val(OrderId);
                    $("#oop").text(quotationNumber);
                    $("#pop").val(productionPlanId);
                    $("#pop").text(productionPlanId);
                    $("#syp").text(styleNumber);
                    $("#syp").val(styleNumberId);
                    $("#prp").val(productDetailId);
                    $("#prp").text(productName);
                    $("#sop").val(sizeId);
                    $("#sop").text(name);
                    layui.form.render('select'); // 重新渲染select元素

                    form.render(null, 'addForm');
                    layer.open({
                        type: 1,
                        title: '产量添加',
                        content: $("#addForm"),
                        area: ['500px', '500px'], // 弹窗大小
                        btn: ['添加产量', '取消'],
                        yes: function (index, layero) {
                            // 获取表单数据
                            var formData = data.field;
                            //提交表单代码
                            console.log(formData);
                            let value = $('#fm').serializeArray();
                            $.each(value, function(index,item){
                                data[item.name] = item.value;
                            });
                            let con = JSON.stringify(data);
                            $.ajax({
                                url: "contract/addcuttingDepartment",
                                type: "POST",
                                data: con,
                                dataType: "json",
                                contentType: "application/json;charset=utf-8",
                                success: function (result) {
                                    layer.msg(result.message);
                                }, error: function () {
                                    layer.msg("添加失败");
                                }
                            });
                            layer.close(index); // 关闭弹窗

                            // 刷新表格

                        }
                    });
                }


                // 在这里可以进行您想要的操作，如展示详情、编辑、删除等
                $.ajax( {
                    "url"            :  "contract/getroductionPlan",
                    "type"         :  "get",
                    "data"         :  {productionPlanId:productionPlanId},
                    "dataType" :  "json",
                    // contentType:"application/json;charset=utf-8",
                    "success"  :  function(result) {
                        let opo =''
                        for (let ord in result) {
                            opo +=`

                    `
                        }
                        layui.form.render('select'); // 重新渲染select元素
                    },
                    "error"       :  function() {
                        alert("没有查询到生产计划")
                    }
                } );


            });



        });

</script>
</body>
</html>